package cz.muni.fi.pa165.hauntedhouses.entity;

import cz.muni.fi.pa165.hauntedhouses.dto.AbilityType;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;

/**
 *
 * @author Jan Vyhnanek (374138)
 */
@Entity
public class Ghost implements Serializable {
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    @Column(nullable=false)
    private String name;    
    
    @ManyToMany(fetch= FetchType.EAGER,cascade= CascadeType.REFRESH)
    private List<Ability> abilities;
    
    @ManyToOne (optional=true,cascade= CascadeType.REFRESH)
    private House home;
    
    @Column(nullable=false)
    private String description;
    
    @Column(nullable=false)
    @Temporal(javax.persistence.TemporalType.TIMESTAMP)
    private Date lastHaunted;
    
    @Column(nullable=false)
    private Integer lvl;
    
    @Column(nullable=false)
    private Integer experience;
    
    @Column(nullable=false)
    private AbilityType abilityType;

    public AbilityType getAbilityType() {
        return abilityType;
    }

    public void setAbilityType(AbilityType abilityType) {
        this.abilityType = abilityType;
    }
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Ability> getAbilities() {
        return abilities;
    }

    public void setAbilities(List<Ability> abilities) {
        this.abilities = abilities;
    }

    public House getHome() {
        return home;
    }

    public void setHome(House home) {
        this.home = home;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getLastHaunted() {
        return lastHaunted;
    }

    public void setLastHaunted(Date lastHaunted) {
        this.lastHaunted = lastHaunted;
    }

    public Integer getLvl() {
        return lvl;
    }

    public void setLvl(Integer lvl) {
        this.lvl = lvl;
    }

    public Integer getExperience() {
        return experience;
    }

    public void setExperience(Integer experience) {
        this.experience = experience;
    }   
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 89 * hash + Objects.hashCode(this.id);
        hash = 89 * hash + Objects.hashCode(this.name);
        hash = 89 * hash + Objects.hashCode(this.abilities);
        hash = 89 * hash + Objects.hashCode(this.home);
        hash = 89 * hash + Objects.hashCode(this.description);
        hash = 89 * hash + Objects.hashCode(this.lastHaunted);
        hash = 89 * hash + Objects.hashCode(this.lvl);
        hash = 89 * hash + Objects.hashCode(this.experience);
        hash = 89 * hash + (this.abilityType != null ? this.abilityType.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Ghost other = (Ghost) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        if (!Objects.equals(this.name, other.name)) {
            return false;
        }
        if (!Objects.equals(new ArrayList<Ability>().addAll(this.abilities), new ArrayList<Ability>().addAll(other.abilities))) {
            return false;
        }
        if (!Objects.equals(this.home, other.home)) {
            return false;
        }
        if (!Objects.equals(this.description, other.description)) {
            return false;
        }
        if (!Objects.equals(this.lastHaunted, other.lastHaunted)) {
            return false;
        }
        if (!Objects.equals(this.lvl, other.lvl)) {
            return false;
        }
        if (!Objects.equals(this.experience, other.experience)) {
            return false;
        }
        if (this.abilityType != other.abilityType) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Ghost{" + "id=" + id + ", name=" + name + ", abilities=" + abilities + " description=" + description + ", lastHaunted=" + lastHaunted + ", lvl=" + lvl + ", experience=" + experience + ", abilityType=" + abilityType + '}';
    }    
    
}
